namespace graver.CodeAnalysis.Syntax;

internal static class SyntaxFacts
{
    /// <summary>
    /// 操作符优先级转换
    /// </summary>
    /// <param name="kind"></param>
    /// <returns></returns>
    public static int GetBinaryOperatorPrecedence(this SyntaxKind kind)
    {
        return kind switch
        {
            SyntaxKind.StarToken => 5,
            SyntaxKind.SlashToken => 5,

            SyntaxKind.PlusToken => 4,
            SyntaxKind.MinusToken => 4,

            SyntaxKind.EqualsEqualsToken => 3,
            SyntaxKind.BangEqualsToken => 3,

            SyntaxKind.AmpersandAmpersandToken => 2,

            SyntaxKind.PipePipeToken => 1,

            _ => 0
        };
    }

    /// <summary>
    /// 操作符优先级转换
    /// </summary>
    /// <param name="kind"></param>
    /// <returns></returns>
    public static int GetUnaryOperatorPrecedence(this SyntaxKind kind)
    {
        return kind switch
        {
            SyntaxKind.PlusToken => 6,
            SyntaxKind.MinusToken => 6,
            SyntaxKind.AmpersandAmpersandToken => 6,
            _ => 0
        };
    }

    public static SyntaxKind GetIdentifierKind(string identifierText)
    {
        return identifierText switch
        {
            "true" => SyntaxKind.KeyWordTrue,
            "false" => SyntaxKind.KeyWordFalse,
            _ => SyntaxKind.IdentifierToken
        };
    }
}
